﻿using System;
using System.Windows.Forms;

namespace SPR.GUI
{
    public partial class Configuration : Form
    {
        private static Configuration instance = new Configuration();
        private static SPR ulc = null;

        private Configuration()
        {
            InitializeComponent();

            Version_Label.Text = string.Format("Version: {0}", SPR.Version);
            this.Cooldowns_CheckBox.Checked = SettingsFile.Instance.HandleCooldowns;
            this.extraactionbutton.Checked = SettingsFile.Instance.Handleextraactionbutton;
            this.shouldAoeButton.Checked = SettingsFile.Instance.shouldAOE;
            this.hunterMdPetButton.Checked = SettingsFile.Instance.shoulMDPet;
            this.useCPGButton.Checked = SettingsFile.Instance.shouldUseCPG;
            this.FormClosing += this.SaveSettings;
        }

        public static void Display(SPR ulc)
        {
            Configuration.ulc = ulc;
            if (instance == null || instance.IsDisposed)
            {
                instance = new Configuration();
            }

            if (!instance.Visible)
            {
                instance.Show();
            }
        }

        private void SaveSettings(object sender, EventArgs e)
        {
            SettingsFile.Instance.HandleCooldowns = this.Cooldowns_CheckBox.Checked;
            SettingsFile.Instance.Handleextraactionbutton = this.extraactionbutton.Checked;
            SettingsFile.Instance.shouldAOE = this.shouldAoeButton.Checked;
            SettingsFile.Instance.shoulMDPet = this.hunterMdPetButton.Checked;
            SettingsFile.Instance.shouldUseCPG = this.useCPGButton.Checked;
            SettingsFile.Instance.Save();
        }

        private void CooldownsCheckBoxCheckedChanged(object sender, EventArgs e)
        {
            this.Cooldowns_CheckBox.CheckedChanged += this.SaveSettings;
        }

        private void ExtraactionbuttonCheckBoxCheckedChanged(object sender, EventArgs e)
        {
            this.extraactionbutton.CheckedChanged += this.SaveSettings;
        }

        private void shouldAoeButton_CheckedChanged(object sender, EventArgs e)
        {
            this.shouldAoeButton.CheckedChanged += this.SaveSettings;
            SPR.Instance.Log("AOE Switched to {0} ", this.shouldAoeButton.Checked);
        }

        private void hunterMdPetButton_CheckedChanged(object sender, EventArgs e)
        {
            this.hunterMdPetButton.CheckedChanged += this.SaveSettings;
        }

        private void useCPGButton_CheckedChanged(object sender, EventArgs e)
        {
            this.useCPGButton.CheckedChanged += this.SaveSettings;
            SPR.Instance.Log("CPG Switched to {0} ", SPR.Instance.AutoCPG);
        }
    }
}
